<template>
  <div>
    <el-form :inline="true">
      <el-form-item>
        <v-distpicker only-province @selected="onSelected" v-if="preRoleType === '1'">
        </v-distpicker>
        <el-select v-model="scrapStockDto.cityCode" placeholder="请选择地市"
                   v-if="scrapStockDto.roleType === 2 && preOfficeType === '0'" @change="onCityChange()">
          <el-option
            v-for="item in addressOption"
            :key="item.code"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </el-form-item>
      <!--网点类型查询-->
      <el-form-item v-if="preRoleType === '1' || preOfficeType === '0'">
        <el-select v-model="scrapStockDto.pointType" placeholder="请选择网点类型" @change="onPointChange()">
          <el-option
            v-for="item1 in pointTypeOptions"
            :key="item1.id"
            :label="item1.name"
            :value="item1.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="scrapStockDto.pointType === 0 && preOfficeType !== '1'">
        <el-select v-model="scrapStockDto.pointId" placeholder="请选择办事处" clearable>
          <el-option
            v-for="item1 in pointOptions"
            :key="item1.id"
            :label="item1.name"
            :value="item1.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="scrapStockDto.pointType === 1 && preOutsourceType !== '0'">
        <el-select v-model="scrapStockDto.pointId" placeholder="请选择外包商" clearable>
          <el-option
            v-for="item1 in outsourceOptions"
            :key="item1.id"
            :label="item1.company"
            :value="item1.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="scrapStockDto.modelId" clearable placeholder="请选择型号">
          <el-option
            v-for="item in allModel"
            :key="item.id"
            :label="item.code"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="YSTSN" v-model="scrapStockDto.ystsn" clearable v-if="preRoleType !== '4' "></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchDate()">查询</el-button>
      </el-form-item>
      <el-form-item v-if="preRoleType === '2' || preRoleType === '3' ">
        <el-dropdown @command="handleCommand">
          <el-button type="primary">导入<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <a href="/static/报废库导入模板.xlsx" download="报废库导入模板.xlsx" style="color:#5a5e66;text-decoration: none ">
              <el-dropdown-item command="handleDownload">模板下载</el-dropdown-item>
            </a>
            <el-dropdown-item command="handleImport">数据导入</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-form-item>
    </el-form>
    <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick(activeName)">
      <el-tab-pane label="未返还" name="unReturn">
        <custom-table
          :data="scrapStockList"
          :columns="columns"
          :tableLoadingFlag="tableLoadingFlag"
          :operationColumn="operationColumn"
          :pagination="pagination">
        </custom-table>
      </el-tab-pane>
      <el-tab-pane label="已返还" name="alreadyReturn">
        <custom-table
          :data="alreadyReturnList"
          :columns="columns"
          :tableLoadingFlag="tableLoadingFlag"
          :operationColumn="operationColumn1"
          :pagination="alreadyPagination">
        </custom-table>
      </el-tab-pane>
    </el-tabs>


    <el-dialog title="维修记录" :visible.sync="detailDialogVisible" :close-on-click-modal="false">
      <repair-list
        :ystsn="ystsn">
      </repair-list>
      <div slot="footer">
        <el-button type="primary" @click="onBtnCancel()">取消</el-button>
      </div>
    </el-dialog>

    <!-- 报废模板导入模态框 -->
    <el-dialog title="模板导入" :visible.sync="uploadVisible"
               :close-on-click-modal="false" :before-close="uploadCancel">
      <div>
        <el-form label-width="80px" ref="uploadForm" :inline="true">
          <el-form-item style="padding-left: 120px">
            <el-upload
              class="upload-demo"
              :action="uploadUrl"
              :headers="myHeaders"
              name="file"
              :on-error="uploadError"
              :on-success="uploadSuccess"
              :before-upload="beforeAvatarUpload"
              multiple
              drag
              :limit="1"
              :file-list="fileList">
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em><br/>只能上传xlsx文件，且不超过10M</div>
            </el-upload>
          </el-form-item>
          <!--显示导入中错误的数据-->
          <div style="height: 200px;overflow-y: auto" v-if="hideTable">
            <custom-table
              :data="wrongDataList"
              :columns="wrongDetailColumns">
            </custom-table>
          </div>
        </el-form>
      </div>
      <div slot="footer">
        <el-button type="primary" @click="uploadCancel()">确定</el-button>
      </div>
    </el-dialog>

    <!--报废品转不良品-->
    <el-dialog title="转不良品" :visible.sync="toBadVisible" width=35% @close="toBadCancel">
      <div text-align="center">
        <el-form :inline="true" ref="toBadForm" :rules="toBadFormRules" :model="toBadDto">
          <el-form-item prop="faultAppearance" label="故障现象 ：">
            <el-select style="width:180px;" v-model="toBadDto.faultAppearance" clearable placeholder="请选择硬件故障现象">
              <el-option
                v-for="item in hardwareFaultAppearance"
                :key="item.id"
                :label="item.appearance"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="backFactory" label="维修工厂 ：">
            <el-select v-model="toBadDto.backFactory" clearable placeholder="请选择返回工厂">
              <el-option
                v-for="item1 in factoryOptions"
                :key="item1.id"
                :label="item1.name"
                :value="item1.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" style="margin-bottom: 5px">
          <el-button type="primary" @click="toBadCancel()">取消</el-button>
          <el-button type="primary" @click="toBadConfirm()">确定</el-button>
        </div>
        <div style="height: 10px">
        </div>
      </div>
    </el-dialog>

    <!--编辑功能模态框-->
    <el-dialog title="编辑" :visible.sync="editVisible" :close-on-click-modal="false">
      <div text-align="center">
        <el-form :model="editDto" label-width="120px" ref="editForm">
          <el-form-item label="型号" prop="model">
            <el-select style="width:180px;" v-model="editDto.modelId" clearable placeholder="请选择型号">
              <el-option
                v-for="item in allModel"
                :key="item.id"
                :label="item.code"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="工厂" prop="factoryName">
            <el-select v-model="editDto.factoryId" placeholder="请选择工厂">
              <el-option
                v-for="item1 in factoryOptions"
                :key="item1.id"
                :label="item1.name"
                :value="item1.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="YSTSN" prop="ystsn">
            <el-input v-model="editDto.ystsn"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editCancel()">取消</el-button>
        <el-button type="primary" @click="editConfirm()">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :destroy-on-close="true"
      :visible.sync="scrapRecordDialog"
      title="设备报废记录"
      width="50%">
      <div style="padding-bottom: 20px">
        <custom-table
          :data="scrapRecordList"
          :columns="scrapRecordColumns"
          :tableLoadingFlag="scrapRecordFlag"
          :operationColumn="scrapRecordColumn">
        </custom-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import CustomTable from '@/components/table/CustomTable'
  import {
    apiGetScrapStockList,
    apiUpdateScrapStockDevice,
    apiGetReturnFactory,
    apiUpdateScrapToBad,
    apiUpdateScrapToGood,
    apiGetScrapRecord
  } from '@/api/stock/index'
  import {
    apiGetCityListByProvinceCode,
    apiGetModelList,
    apiGetAllPointOffice,
    apiGetFaultAppearance
  } from '@/api/dictionary'
  import {getRoleType, getOfficeType, getCityCode, getProvinceCode, getOutsourceType} from '@/utils/token'
  import {parseTime} from '@/utils'
  import {baseInfo} from '@/utils/fetch'
  import store from '@/store'
  import {apiScrapStockReadExcel} from '@/api/excel/excelRead'
  import {apiDownload} from '@/api/approve/scrap'
  import RepairList from '../../../components/table/RepairList.vue'
  import {apiGetOutsourcerList} from '@/api/basic/info/outsourcer'
  import {apiGetOfficeList} from '@/api/basic/info/inside/office'

  export default {
    components: {
      RepairList,
      CustomTable
    },
    created () {
      this.preOfficeType = getOfficeType()
      this.preOutsourceType = getOutsourceType()
      this.preRoleType = getRoleType()
      let listQuery = {
        pageNumber: this.pagination.currentPage,
        pageSize: this.pagination.pageSize
      }
      if (getRoleType() === '3') {
        this.scrapStockDto.provinceCode = getProvinceCode()
        this.scrapStockDto.pointType = 1
        if (getOutsourceType() === '0') {
          this.scrapStockDto.cityCode = getCityCode()
        }
      }
      if (getRoleType() === '2') {
        this.scrapStockDto.provinceCode = getProvinceCode()
        this.scrapStockDto.roleType = 2
        listQuery.province = getProvinceCode()
        if (getOfficeType() === '1') {
          listQuery.city = getCityCode()
          this.scrapStockDto.cityCode = getCityCode()
        }
        this.selectedAddressInit()
      } else if (getRoleType() === '1') {
        this.operationColumn = {
          width: '100',
          operations: [
            {name: '维修病例', callback: this.onBtnRepairHistory},
            {name: '编辑', callback: this.handleEdit, page: 'scrapStockEdit'}
          ]
        }
      }
      this.getAllModel()
      this.selectFactoryList()
      this.selectHardWareFaultAppearance()
      this.getOffice()
      this.getOutsource()
      this.searchDate()
    },
    data () {
      return {
        // 初始化页面为未返还
        tab: 0,
        activeName: 'unReturn',
        // 办事处
        pointOptions: [],
        // 外包商
        outsourceOptions: [],
        uploadUrl: baseInfo() + '/api/v1/upload',
        myHeaders: {'access_token': store.getters.token},
        // 上传文件显示
        fileList: [],
        // 文件上传路径
        importFileUrl: baseInfo() + '/api/v1/upload',
        // 文件上传参数
        upLoadData: {},
        filePath: '',
        editVisible: false,
        // 工厂
        factoryOptions: [],
        // 设备故障类型列表
        hardwareFaultAppearance: [],
        uploadVisible: false,
        hideTable: false,
        // 转不良品模态框标志量
        toBadVisible: false,
        wrongDetailColumns: [
          {label: '错误行号', name: 'wrongRowNO', width: '77', height: '40', align: 'center'},
          {label: '错误原因', name: 'reason', width: '120', height: '40', align: 'center'},
          {label: '品牌', name: 'brand', align: 'center'},
          {label: '型号', name: 'model', align: 'center'},
          {label: 'YSTSN', name: 'ystsn', align: 'center'}
        ],
        tableLoadingFlag: false,
        // 不良品库存一览表
        columns: [
          {label: 'ID', name: 'id', width: '80', align: 'center'},
          {label: '品牌', name: 'brand', align: 'center'},
          {label: '型号', name: 'model', align: 'center'},
          {label: '省份', name: 'provinceName', align: 'center'},
          {label: '城市', name: 'cityName', align: 'center'},
          {label: 'YSTSN', name: 'ystsn', align: 'center'},
          {label: '入库时间', name: 'instockTime', align: 'center', formatter: this.formatTime},
          {label: '生产厂商', name: 'factory', align: 'center'}
        ],
        scrapStockList: [],
        alreadyReturnList: [],
        addressOption: [],
        preOfficeType: null,
        // 编辑DTO
        editDto: {
          ystsn: '',
          modelId: '',
          id: '',
          factoryId: '',
          status: '',
          isReturn: ''
        },
        // 转不良品DTO
        toBadDto: {
          ystsn: '',
          faultAppearance: '',
          backFactory: ''
        },
        // 转良品DTO
        toGoodDto: {
          ystsn: ''
        },
        scrapStockDto: {
          provinceCode: '',
          cityCode: '',
          pointType: 0,
          pointId: '',
          roleType: 1,
          // 返还状态(0：未返还 1：已返还)
          status: '',
          modelId: undefined,
          ystsn: ''
        },
        operationColumn: {
          width: '100',
          operations: [
            {name: '维修病例', callback: this.onBtnRepairHistory},
            {name: '转不良品', callback: this.transferToBad},
            {name: '转良品', callback: this.transferToGood},
            {name: '展开下载附件', callback: this.scrapRecord}
          ]
        },
        operationColumn1: {
          width: '100',
          operations: [
            {name: '维修病例', callback: this.onBtnRepairHistory},
            {name: '展开下载附件', callback: this.scrapRecord}
          ]
        },
        detailTableLoadingFlag: false,
        detailDialogVisible: false,
        pagination: this.getData(this.getScrapStockList),
        alreadyPagination: this.getData(this.getScrapStockList),
        pointTypeOptions: [
          {
            'id': 0,
            'name': '办事处'
          },
          {
            'id': 1,
            'name': '外包商'
          }
        ],
        preRoleType: getRoleType(),
        ystsn: '',
        allModel: [],
        toBadFormRules: {
          faultAppearance: [
            {required: true, message: '请选择设备故障类型', trigger: 'change'}
          ],
          backFactory: [
            {required: true, message: '请选择返还工厂', trigger: 'change'}
          ]
        },
        scrapRecordDialog: false,
        scrapRecordList: [],
        scrapRecordColumns: [
          {label: '工厂维修ID', name: 'repairId', width: '80', align: 'center'},
          {label: '批次号', name: 'batch', width: '180', align: 'center'},
          {label: 'YSTSN', name: 'ystsn', align: 'center'},
          {label: '工厂维修结果', name: 'repairResult', width: '80', align: 'center'}
        ],
        scrapRecordFlag: false,
        scrapRecordColumn: {
          width: '80',
          operations: [
            {name: '下载附件', callback: this.downloadFile, page: 'scrap'}
          ]
        }
      }
    },
    methods: {
      handleClick (activeName) {
        if (activeName === 'unReturn') {
          this.tab = 0
          this.scrapStockDto.status = 0
        } else if (activeName === 'alreadyReturn') {
          this.tab = 1
          this.scrapStockDto.status = 1
        }
        this.searchDate()
      },
      uploadCancel () {
        this.uploadVisible = false
        this.wrongDataList = []
        this.fileList = []
        this.hideTable = false
        this.$refs['uploadForm'].resetFields()
      },
      handleCommand (command) {
        if (command === 'handleImport') {
          this.dialogType = 'upload'
          this.uploadVisible = true
        } else if (command === 'handleDownload') {
        }
      },
      uploadSuccess (response) {
        this.$message({
          showClose: true,
          message: '上传文件成功!'
        })
        let filePath = response.data
        this.excelRead(filePath)
      },
      // 上传错误
      uploadError () {
        this.$message({
          showClose: true,
          message: '上传失败，请重试！'
        })
      },
      // 上传前对文件的大小的判断
      beforeAvatarUpload (file) {
        const extension = file.name.split('.')[1] === 'xlsx'
        const isLt2M = file.size / 1024 / 1024 < 10
        if (!extension) {
          this.$message({
            showClose: true,
            message: '上传模板只能是 xlsx 格式!'
          })
        }
        if (!isLt2M) {
          this.$message({
            showClose: true,
            message: '上传模板大小不能超过 10MB!'
          })
        }
        return extension && isLt2M
      },
      excelRead (filePath) {
        apiScrapStockReadExcel({'filePath': filePath}).then(response => {
          if (response.data) {
            this.wrongDataList = response.data
            this.hideTable = true
          } else {
            this.$message({
              showClose: true,
              message: '导入执行中，请稍后',
              type: 'success'
            })
            this.hideTable = false
            this.getScrapStockList({
              pageNumber: this.pagination.currentPage,
              pageSize: this.pagination.pageSize
            })
          }
          this.fileList = []
        })
      },
      // 地址初始化
      selectedAddressInit () {
        let listquery = {
          province: getProvinceCode()
        }
        apiGetCityListByProvinceCode(listquery).then(response => {
          let cityList = response.data
          let city = []
          let temp = {}
          for (let i in cityList) {
            if (!temp[cityList[i].name]) {
              temp[cityList[i].name] = cityList[i].code
            }
          }
          city.push({'name': '全部地市', 'code': ''})
          for (let k in temp) {
            city.push({'name': k, 'code': temp[k]})
          }
          this.addressOption = city
        }).catch(() => {
          this.tableLoadingFlag = false
        })
      },
      getScrapStockList (listQuery) {
        if (undefined === listQuery.province) {
          if (this.scrapStockDto.provinceCode === '') {
            if (getRoleType() === '2') {
              listQuery.province = getProvinceCode()
              if (getOfficeType === '1') {
                listQuery.city = getCityCode()
              }
            }
          } else {
            listQuery.province = this.scrapStockDto.provinceCode
          }
        }
        if (undefined === listQuery.modelId) {
          listQuery.modelId = this.scrapStockDto.modelId
        }
        if (listQuery.ystsn === undefined) {
          listQuery.ystsn = this.scrapStockDto.ystsn
        }
        if (!listQuery.status) {
          listQuery.status = this.scrapStockDto.status
        }
        if (!listQuery.pointType) {
          listQuery.pointType = this.scrapStockDto.pointType
        }
        if (!listQuery.pointId) {
          listQuery.pointId = this.scrapStockDto.pointId
        }
        this.tableLoadingFlag = true
        apiGetScrapStockList(listQuery).then(response => {
          // 待返还tab
          if (this.tab === 0) {
            this.scrapStockList = response.data
            this.pagination.totalRecords = response.totalRecords
          } else if (this.tab === 1) {
            this.alreadyReturnList = response.data
            this.alreadyPagination.totalRecords = response.totalRecords
          }
          this.tableLoadingFlag = false
        }).catch(() => {
          this.tableLoadingFlag = false
        })
      },
      onSelected (data) {             // 省市区联动回调
        this.scrapStockDto.provinceCode = data.province.code
      },
      // 条件查询
      searchDate () {
        let listQuery = {
          pageNumber: this.pagination.currentPage,
          pageSize: this.pagination.pageSize,
          province: this.scrapStockDto.provinceCode,
          city: this.scrapStockDto.cityCode,
          pointType: this.scrapStockDto.pointType,
          pointId: this.scrapStockDto.pointId,
          status: this.scrapStockDto.status,
          modelId: this.scrapStockDto.modelId,
          ystsn: this.scrapStockDto.ystsn
        }
        if (getRoleType() === '2') {
          listQuery.province = getProvinceCode()
        }
        this.scrapStockList = []
        this.pagination.totalRecords = 0
        this.getScrapStockList(listQuery)
        this.pagination.currentPage = 1
        this.pagination.pageSize = 10
      },
      // 用户返还
      returnCustomer (row) {
        this.$router.push(
          {
            path: '/stock/logistic',
            query: {
              id: row.id,
              batch: row.batch,
              ystsn: row.ystsn,
              type: 1
            }
          })
      },
      // 弹出维修一览界面
      onBtnRepairHistory (row) {
        this.detailDialogVisible = true
        this.ystsn = row.ystsn
      },
      // 转不良品
      transferToBad (row) {
        this.toBadVisible = true
        this.toBadDto.ystsn = row.ystsn
      },
      // 取消转不良品
      toBadCancel () {
        this.toBadVisible = false
        this.$refs['toBadForm'].resetFields()
        this.toBadDto = {
          ystsn: '',
          faultAppearance: '',
          backFactory: ''
        }
      },
      // 确认转不良品
      toBadConfirm () {
        this.$refs['toBadForm'].validate((valid) => {
          if (valid) {
            apiUpdateScrapToBad(this.toBadDto).then(() => {
              this.$message({
                showClose: true,
                type: 'success',
                message: '转不良品成功!'
              })
              this.toBadDto = {
                ystsn: '',
                faultAppearance: '',
                backFactory: ''
              }
              this.$refs['toBadForm'].resetFields()
              this.toBadVisible = false
              this.searchDate()
            })
          } else {
            return false
          }
        })
      },
      // 转良品
      transferToGood (row) {
        this.$confirm('确定转入良品库？', '转入良品库', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.toGoodDto.ystsn = row.ystsn
          apiUpdateScrapToGood(this.toGoodDto).then(() => {
            this.$message({
              showClose: true,
              type: 'success',
              message: '转良品成功!'
            })
            this.searchDate()
          })
        })
      },
      scrapRecord (row) {
        this.scrapRecordDialog = true
        this.scrapRecordFlag = true
        apiGetScrapRecord(row.ystsn).then(resp => {
          this.scrapRecordList = resp.data
          this.scrapRecordFlag = false
        }).catch(() => {
          this.scrapRecordFlag = false
        })
      },
      // 下载报废附件(不可修复鉴定表)
      downloadFile (row) {
        let fileNameArr = row.filePath.split('.')
        let paramsPost = {
          id: row.repairId
        }
        if (fileNameArr[fileNameArr.length - 1] === 'xlsx') {
          apiDownload(paramsPost).then(response => {
            let blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
            window.location.href = URL.createObjectURL(blob)
          }).catch(() => {
          })
        } else if (fileNameArr[fileNameArr.length - 1] === 'zip') {
          apiDownload(paramsPost).then(response => {
            let blob = new Blob([response.data], {type: 'application/x-zip-compressed'})
            window.location.href = URL.createObjectURL(blob)
          }).catch(() => {
          })
        }
      },
      // 关闭弹出框
      onBtnCancel () {
        this.detailTableLoadingFlag = false
        this.tableLoadingFlag = false
        this.detailDialogVisible = false
      },
      formatTime (row, column, cellValue) {
        return parseTime(cellValue)
      },
      getAllModel () {
        apiGetModelList().then(response => {
          this.allModel = response.data
        })
      },
      // 编辑按钮
      handleEdit (row) {
        this.editVisible = true
        this.editDto.id = row.id
        this.editDto.ystsn = row.ystsn
        this.editDto.status = row.status
        this.editDto.isReturn = row.isReturn
        this.editDto.factoryId = row.factoryId
        this.editDto.modelId = row.modelId
      },
      editCancel () {
        this.editVisible = false
        this.$refs['editForm'].resetFields()
        this.editDto = {
          ystsn: '',
          modelId: '',
          factoryId: ''
        }
      },
      // 确认编辑
      editConfirm () {
        apiUpdateScrapStockDevice(this.editDto).then(() => {
          this.$message({
            showClose: true,
            message: '编辑成功',
            type: 'success'
          })
          this.editCancel()
          this.searchDate()
        })
      },
      // 返还工厂初始化
      selectFactoryList () {
        apiGetReturnFactory().then(response => {
          let factoryList = response.data
          let factory = []
          let temp = {}
          for (let i in factoryList) {
            if (!temp[factoryList[i].name]) {
              temp[factoryList[i].name] = factoryList[i].id
            }
          }
          for (let k in temp) {
            factory.push({'name': k, 'id': temp[k]})
          }
          this.factoryOptions = factory
        }).catch(() => {
        })
      },
      // 设备故障类型列表初始化
      selectHardWareFaultAppearance () {
        let listQuery = {
          faultType: 1
        }
        apiGetFaultAppearance(listQuery).then(response => {
          this.hardwareFaultAppearance = response.data
        })
      },
      onCityChange () {
        if (this.scrapStockDto.pointType === 0) {
          let listQuery = {
            province: this.scrapStockDto.provinceCode,
            city: this.scrapStockDto.cityCode
          }
          this.pointOptions = []
          this.getOfficeByCity(listQuery)
        } else {
          let listQuery = {
            provinceCode: this.scrapStockDto.provinceCode,
            cityCode: this.scrapStockDto.cityCode
          }
          this.outsourceOptions = []
          this.getOutsourceByCity(listQuery)
        }
      },
      onPointChange () {
        if (this.scrapStockDto.pointType === 0) {
          let listQuery = {
            province: this.scrapStockDto.provinceCode,
            city: this.scrapStockDto.cityCode
          }
          this.pointOptions = []
          this.getOfficeByCity(listQuery)
        } else {
          let listQuery = {
            provinceCode: this.scrapStockDto.provinceCode,
            cityCode: this.scrapStockDto.cityCode
          }
          this.outsourceOptions = []
          this.getOutsourceByCity(listQuery)
        }
      },
      // 获取网点一览
      getOffice () {
        let listQuery = {
          provinceCode: this.scrapStockDto.provinceCode,
          pageNumber: 1,
          pageSize: 100
        }
        apiGetOfficeList(listQuery).then(response => {
          this.pointOptions = response.data
        })
      },
      // 获取外包商一览
      getOutsource () {
        let listQuery = {
          provinceCode: this.scrapStockDto.provinceCode,
          pageNumber: 1,
          pageSize: 100
        }
        apiGetOutsourcerList(listQuery).then(response => {
          this.outsourceOptions = response.data
        })
      },
      // 按地区条件获取网点
      getOfficeByCity (listQuery) {
        this.scrapStockDto.pointId = ''
        apiGetAllPointOffice(listQuery).then(response => {
          this.pointOptions = response.data
        })
      },
      // 按地区获取外包商
      getOutsourceByCity (listQuery) {
        this.scrapStockDto.pointId = ''
        listQuery.pageNumber = 1
        listQuery.pageSize = 100
        apiGetOutsourcerList(listQuery).then(response => {
          this.outsourceOptions = response.data
        })
      }
    }
  }
</script>
